
import express from 'express'

import ResponseHelper from '../ResponseHelper';
import TestPaperService from '../../services/TestPaperService';

const router = express.Router();

/**
 * create
 */
router.post('/', async (req, res, next) => {
  const body = req.body;

  try {
    const result = await TestPaperService.create(body)
    ResponseHelper.send(result, res);
  } catch (err) {
    next()
  }
})

router.get('/findByPage', async (req, res, next) => {
  // @ts-ignore
  // const class_id: string = req.query.class_id || ''
  const page = req.query.page || 1
  const limit = req.query.limit || 10

  try {
    const result = await TestPaperService.findByPage(+page, +limit)

    ResponseHelper.send(result, res)

  } catch (err) {
    next()
  }
})

router.get('/exam/:id', async (req, res, next) => {
  const id = req.params.id || ""

  const result = await TestPaperService.findById(id)
  ResponseHelper.send(result, res)
})

router.delete('/:id', async (req, res, next) => {
  const id = req.params.id || ''
  const result = await TestPaperService.delete(id)

  ResponseHelper.send(result, res)
})

export default router 